//
//  BaseTableViewCell.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/3.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "BaseTableViewCell.h"

@implementation BaseTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString * cellID = @"BaseTableViewCell";
    BaseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell==nil) {
        cell = [[BaseTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = WHITE_COLOR;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
    
}

//- (UILabel *)baseLab{
//    if (!_baseLab) {
//        UILabel * baseLab = [UILabel new];
//        self.baseLab = baseLab;
//        [self.contentView addSubview:baseLab];
//    }
//    return _baseLab;
//
//}

- (UIImageView *)baseIndicator{
    if (!_baseIndicator) {
        UIImageView * baseIndicator = [UIImageView new];
        self.baseIndicator = baseIndicator;
        [self.contentView addSubview:baseIndicator];
    }
    return _baseIndicator;
}

- (void)setupSubviews{
    if (!_baseLab) {
       _baseLab = [UILabel new];
    }
    [self.contentView addSubview:_baseLab];
    
    _baseLab.font = XJFONTSET_R(14);
    _baseLab.textColor = XJCOLOR_RGB(17, 17, 17);
    _baseLab.text = _baseTitle;

    
    self.baseIndicator.image= [UIImage imageNamed:@"direction_right_black"];
    self.baseIndicator.sd_layout
    .centerYEqualToView(self.contentView)
    .rightSpaceToView(self.contentView, ADAPTWidth(20))
    .widthIs(12)
    .heightIs(12);
    
}

- (void)setBaseTitle:(NSString *)baseTitle{
    
    _baseTitle      =   baseTitle;
    _baseLab.text   =   _baseTitle;
    
    XJLog(@"   %@  ",baseTitle);
    
    if (![baseTitle isEqualToString:@"退出登录"]) {
        CGFloat baseLabW = [UILabel labelWithLabel:_baseLab getWidthWithTitle:_baseTitle font:_baseLab.font];
        CGFloat baseLabH = [UILabel labelWithLabel:_baseLab getHeightByWidth:baseLabW title: _baseTitle font:_baseLab.font];
        _baseLab.sd_layout
        .leftSpaceToView(self.contentView, ADAPTWidth(20))
        .centerYEqualToView(self.contentView)
        .widthIs(baseLabW)
        .heightIs(baseLabH);
    }else{
        CGFloat baseLabW = [UILabel labelWithLabel:_baseLab getWidthWithTitle:_baseTitle font:_baseLab.font];
        CGFloat baseLabH = [UILabel labelWithLabel:_baseLab getHeightByWidth:baseLabW title: _baseTitle font:_baseLab.font];
        _baseLab.sd_layout
        .centerXEqualToView(self.contentView)
        .centerYEqualToView(self.contentView)
        .widthIs(baseLabW)
        .heightIs(baseLabH);
        
    }
    

}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
